package com.carol.lmsbe.controller;

import com.carol.lmsbe.common.Result;
import com.carol.lmsbe.dto.ConsumableStatisticsResponse;
import com.carol.lmsbe.dto.EquipmentStatisticsResponse;
import com.carol.lmsbe.dto.StatisticsQueryRequest;
import com.carol.lmsbe.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 统计控制器
 */
@RestController
@RequestMapping("/api/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 获取设备统计信息
     */
    @GetMapping("/equipment")
    @PreAuthorize("hasAnyRole('ADMIN', 'LEADER', 'LAB_MANAGER')")
    public Result<EquipmentStatisticsResponse> getEquipmentStatistics(StatisticsQueryRequest request) {
        EquipmentStatisticsResponse statistics = statisticsService.getEquipmentStatistics(request);
        return Result.success(statistics);
    }

    /**
     * 获取易耗品统计信息
     */
    @GetMapping("/consumable")
    @PreAuthorize("hasAnyRole('ADMIN', 'LEADER', 'LAB_MANAGER')")
    public Result<ConsumableStatisticsResponse> getConsumableStatistics(StatisticsQueryRequest request) {
        ConsumableStatisticsResponse statistics = statisticsService.getConsumableStatistics(request);
        return Result.success(statistics);
    }

    /**
     * 获取设备使用趋势
     */
    @GetMapping("/equipment/trend")
    @PreAuthorize("hasAnyRole('ADMIN', 'LEADER', 'LAB_MANAGER')")
    public Result<EquipmentStatisticsResponse.UsageTrend> getEquipmentUsageTrend(StatisticsQueryRequest request) {
        EquipmentStatisticsResponse.UsageTrend trend = statisticsService.getEquipmentUsageTrend(request);
        return Result.success(trend);
    }

    /**
     * 获取易耗品消耗趋势
     */
    @GetMapping("/consumable/trend")
    @PreAuthorize("hasAnyRole('ADMIN', 'LEADER', 'LAB_MANAGER')")
    public Result<ConsumableStatisticsResponse.ConsumptionTrend> getConsumableConsumptionTrend(StatisticsQueryRequest request) {
        ConsumableStatisticsResponse.ConsumptionTrend trend = statisticsService.getConsumableConsumptionTrend(request);
        return Result.success(trend);
    }
}
